777C - Alyona and Spreadsheet - CodeForces Solution


binary search data structures dp greedy implementation two pointers *1600

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;
#define os ordered_set
#define oms ordered_multiset
#define int long long int
#define ull unsigned long long int
#define F first
#define S second
#define pb push_back
#define MSB(x) (63 - __builtin_clzll(x))
#define rep(i, st, end) for(int i = st; i < end; i++)
#define all(x) (x).begin(),(x).end()
#define pr(x) cout<<x<<'\n'
#define prd(x) cout<<x<<endl
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef map<int, int> mii;
const int mod = 1000000007;
using ii = pair<int, int>;

void solve(){
    int n, m;
    cin>>n>>m;
    int grid[n+1][m+1];
    memset(grid, 0, sizeof(grid));
    rep(i,1,n+1){
        rep(j,1,m+1){
            cin>>grid[i][j];
        }
    }
    int arr[n+1][m+1];
    memset(arr, 0, sizeof(arr));
    for(int j=1; j<=m; j++){
        for(int i=1; i<=n; i++){
            if(grid[i][j] >= grid[i-1][j]){
                arr[i][j] = arr[i-1][j] + 1;
            }
            else{
                arr[i][j] = 1;
            }
        }
    }
    int best[n+1] = {0};
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            best[i] = max(best[i], arr[i][j]);   
        }
    }
    
    int q;
    cin>>q;
    while(q--){
        int l, r;
        cin>>l>>r;
        if(best[r] - 1 >= r - l){
            pr("Yes");
        }
        else{
            pr("No");
        }
    }
}


// always check indexing if using some kindof offset
// if nested loop, check if involved array indices are correct
// for bitmask dp, iterative, first itearate on mask then on others
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);


    int t = 1; 
    // cin>>t; 
    for(int i=1; i<=t; i++){
        // cout << "Case #" << t << 
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs